//
//  MainIndexDataFactory.cpp
//  Chart
//
//  Created by ma xiaoyang on 6/18/13.
//
//

#include "MainIndexDataFactory.h"
#include "YTXChartTools.h"
#include "MA.h"
#include "YTXChartCommon.h"
#include <cmath>

using namespace ytx;
using namespace std;

MainIndexDataFactory::MainIndexDataFactory()
{

}

MainIndexDataFactory::~MainIndexDataFactory()
{

}

#define YTX_GET_MAIN_INDEX(__index__, __indexConfig__) \
__index__->clearIfParentDataChanged(data);\
if(!__index__->hasData() || __index__->isChange(data, __indexConfig__)){ \
__index__->para = __indexConfig__;\
__index__->calculate(data); \
} \
else if(update){ \
__index__->updateLastest(data); \
} \
__index__->initInfo(data); \
return __index__;

void MainIndexDataFactory::factory(const IndexConfig indexConfig)
{
    switch (indexConfig.indexType) {
        case IndexType::BOLLIN:
            SAFEDELETE(bollin);
            bollin = new BOLLIN(indexConfig);
            break;
        case IndexType::TJ:
            SAFEDELETE(tj);
            tj = new TJ(indexConfig);
            break;
        case IndexType::MA:
            SAFEDELETE(ma);
            ma = new MA(indexConfig);
            break;
        case IndexType::QK:
            SAFEDELETE(qk);
            qk = new QK(indexConfig);
            break;
        case IndexType::QKT:
            SAFEDELETE(qkt);
            qkt = new QKT(indexConfig);
            break;
        case IndexType::GameMatrix:
            SAFEDELETE(gameMatrix);
            gameMatrix = new GameMatrix(indexConfig);
            break;
        case IndexType::HJJT:
            SAFEDELETE(hjjt);
            hjjt = new HJJT(indexConfig);
            break;
        default:
            break;
    }
}

IndexData * MainIndexDataFactory::getIndexData(IndexConfig indexConfig, bool update)
{
    switch (indexConfig.indexType) {
        case IndexType::BOLLIN:
            return getBOLLIN(indexConfig, update);
        case IndexType::TJ:
            return getTJ(indexConfig, update);
        case IndexType::QK:
            return getQK(indexConfig, update);
        case IndexType::QKT:
            return getQKT(indexConfig, update);
        case IndexType::GameMatrix:
            return getGameMatrix(indexConfig, update);
        case IndexType::HJJT:
            return getHJJT(indexConfig, update);
        case IndexType::MA:
        default:
            return getMA(indexConfig, update);
    }
}




IndexData* MainIndexDataFactory::getMA(IndexConfig indexConfig, bool update)
{
    ma->para = indexConfig;
    YTX_GET_MAIN_INDEX(ma, indexConfig)
}

IndexData* MainIndexDataFactory::getBOLLIN(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(bollin, indexConfig)
}

IndexData* MainIndexDataFactory::getTJ(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(tj, indexConfig)
}

IndexData* MainIndexDataFactory::getQK(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(qk, indexConfig)
}

IndexData* MainIndexDataFactory::getQKT(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(qkt, indexConfig)
}

IndexData* MainIndexDataFactory::getGameMatrix(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(gameMatrix, indexConfig)
}

IndexData* MainIndexDataFactory::getHJJT(IndexConfig indexConfig, bool update)
{
    YTX_GET_MAIN_INDEX(hjjt, indexConfig)
}
